//
//  UIImage+XMCutImage.h
//  XMKit
//
//  Created by chenming on 2017/11/1.
//  Copyright © 2017年 ChenXiaoMing. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN
// 简单指针对象都被假定为nonnull

@interface UIImage (XMCutImage)

/** 中心拉伸的图片 */
// instancetype == UIImage
+ (UIImage *)xm_stretchableImageNamed:(NSString *)name;

/** 图片缩小居中显示(清晰) */
+ (UIImage *)xm_cutImageRect:(CGRect)rect image:(UIImage *)image;

/** 消除图片系统默认蓝色 */ 
+ (UIImage *)xm_imageModeAlwaysOriginal:(NSString *)imageName;

/** 压缩图片 */
+ (UIImage*)xm_originImage:(UIImage *)image scaleToSize:(CGSize)size;

/** 通过颜色获取一张宽高都为1px的图片 */
+ (UIImage *)xm_imageWithColor:(UIColor *)color;

/** 通过颜色获取一张规定尺寸的图片 */
+ (UIImage *)xm_imageWithColor:(UIColor *)color size:(CGSize)size;


+ (UIImage *)imageCompressForWidth:(UIImage *)sourceImage targetWidth:(CGFloat)defineWidth;

/** 将图片裁剪成一张圆形图片 */
- (UIImage *)xm_clipCircleImageWithBorder:(CGFloat)borderWidth withColor:(UIColor *)borderColor;

/** 将图片压缩到指定宽度 */
- (UIImage *)xm_compressWithWidth:(CGFloat)width;

/** 将图片在子线程中压缩，block在主线层回调，保证压缩到指定文件大小，尽量减少失真 */
- (void)xm_compressToDataLength:(NSInteger)length withBlock:(void(^)(NSData *data))block;

/** 尽量将图片压缩到指定大小，不一定满足条件 */
- (void)xm_tryCompressToDataLength:(NSInteger)length withBlock:(void(^)(NSData *data))block;

/** 快速将图片压缩到指定大小，失真严重 */
- (void)xm_fastCompressToDataLength:(NSInteger)length withBlock:(void(^)(NSData *data))block;

/** 通过修改r.g.b像素点来处理图片 */
- (void)xm_fliterImageWithFliterBlock:(void(^)(int *red, int *green, int *blue))Fliterblock success:(void(^)(UIImage *image))success;

@end

NS_ASSUME_NONNULL_END
